from fastapi import APIRouter, UploadFile, File

from code.app.services.oss import OssManager
from code.app.services.response import Response

# 文件管理接口路由
file_app = APIRouter()
# 创建一个OSS管理实例
oss_manager = OssManager()


@file_app.post("/file/upload")
async def upload_file(file: UploadFile = File(...)) -> Response:
    file_content = await file.read()
    file_url = oss_manager.upload_file(file.filename, file_content)
    return Response.success(data=file_url)
